/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;

/**
 *
 * @author PC
 */
public class GaDAO {
     public static ResultSet TimKiemTatCa() {
        try {
            Connection conn = DBConnect.Connect();
            String sql = "select g.ID,g.GHI_CHU,g.NGAY_TAO,g.TEN,n.HO_TEN \n"
                    +"from GA g, NGUOI_DUNG n,NHAN_VIEN nv\n" 
                    +"where g.NGUOI_CHINH_SUA=nv.ID and nv.NGUOI_DUNG=n.ID";
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sql);
          //  conn.close();
            return rs;

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getStackTrace(), "Thông báo lỗi", JOptionPane.OK_OPTION);
            return null;
        }

    }
      public static ResultSet BaoCao(int ga) {
        try {
            Connection conn = DBConnect.Connect();
            String sql = "select  v.CHUYEN , count(v.ID) as SL from VE v , GA g where g.ID = v.GA_DEN and v.TINH_TRANG_VE = 1 and v.ga_den = ? group by  v.CHUYEN ";
            PreparedStatement pst = conn.prepareStatement(sql);
             pst.setInt(1, ga);
          //  Statement st = conn.createStatement();
            ResultSet rs = pst.executeQuery();
          //  conn.close();
            return rs;

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getStackTrace(), "Thông báo lỗi", JOptionPane.OK_OPTION);
            return null;
        }

    }
      public static boolean KiemTraTonTai(String MaNV)
    {
        try
        {
            Connection con = DBConnect.Connect();
            String sql = "Select * From Ga Where ID like ?";
            
            PreparedStatement ps = con.prepareStatement(sql);
            ps.setString(1, MaNV);
            
            ResultSet rs = ps.executeQuery();
            
            if (rs.next())
                return true;
        }
        catch (Exception ex)
        {
        }
        return false;
    }
}
